﻿using Jinjia.Approve.IRepository.JJFlow;
using Jinjia.Approve.IService.JJFlow.Approvers;
using Jinjia.Approve.Model.VM;
using JinJia.Core.Base.Exceptions;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Jinjia.Approve.Service.JJFlow.Approvers
{
    public class AdSettlementDirectorApproversByHrId : IJJApprovers
    {
        private readonly IJJApproversRepository _jjApproversRepository;

        public AdSettlementDirectorApproversByHrId(IJJApproversRepository jjApproversRepository)
        {
            _jjApproversRepository = jjApproversRepository;
        }

        public async Task<List<int>> GetInstanceNodeEmpInfo(string biz_order_id, int start_user = 0, string depart_id = "0", Dictionary<string, string> dic = null)
        {
            if (!int.TryParse(biz_order_id, out int master_id)) throw new ArgumentException("参数有误！");

            var settlement_model = _jjApproversRepository.GetAdSettlementData(master_id);

            if (settlement_model == null)
            {
                throw new BusinessException("结算单数据不存在！");
            }

            var director_models = _jjApproversRepository.GetSettlementHrDirectorDatas(settlement_model.hr_id);

            if (!director_models.Any())
            {
                throw new BusinessException("红人商务配置不正确！");
            }

            var director_ids = director_models.Select(o => o.director_id).ToList();

            //先写死吧，后面提供映射关系了再回头来写。。。
            //return new List<int> { 1388, 1732, 2395, 2435, 1178, 2462, 1368, 2358, director_model.director_id };
            return await Task.FromResult(director_ids);
        }
    }
}
